{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="WAP_CSS/member_apply_withdrawal.css">
<style>
	.password-div input{
		opacity: 0%;
		width: 100px;
	}
</style>
{/block} 
{block name="main"}
{php}
	$balance_config = api("System.Config.balanceWithdraw");
	$balance_config = $balance_config['data'];
 	$poundage = $balance_config['value']["withdraw_multiple"];
	$cash = $balance_config['value']["withdraw_cash_min"];
	$withdraw_message = $balance_config['value']["withdraw_message"];

	$account = api('System.Member.memberCoin');
	$account = $account['data'];

{/php}

<div class="pay-password-bg" style="display: none" onclick="closePayPassword()"></div>

<div class="pay-pass-bg-wrapper"  style="display: none" >
	<div class="password-div">
		<div class="pay-password-top">
			请输入支付密码
		</div>
		<div class="password-input-wrapper">
			<label for="password" class="password-lable">
				<ul>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
				</ul>
				<input id="password" type="text" name="password" maxlength="6">
			</label>
		</div>
	</div>
</div>

<div class="panel">
	<span>{:lang('member_coin')}：</span>
	<span class="ns-text-color text18" id="Amount">¥{$account}</span>
</div>

<div style="display: flex">
	<div style="flex: 0 0 80px;background-color: white" class="s-center">
		<span>会员ID</span>
	</div>
	<div style="flex: 1">
		<input type="text" id="user_name" placeholder="请输入转入会员账号">
	</div>
</div>
<div style="display: flex">
	<div style="flex: 0 0 80px;background-color: white" class="s-center">
		<span>姓名</span>
	</div>
	<div style="flex: 1">
		<input type="text" id="nick_name" placeholder="请输入转入会员姓名">
	</div>
</div>

<div style="display: flex">
	<div style="flex: 0 0 80px;background-color: white" class="s-center">
		<span>数量</span>
	</div>
	<div style="flex: 1">
		<input type="number" id="money" placeholder="请输入转账数量">
	</div>
</div>


	<div class="tip-text ns-text-color">转账最小10{:lang('member_coin')}，必须为10的倍数。</div>

	<div class="btn-wrap">
		<a href="javascript:;" onclick="showPayPasswordDlg()" class="button ns-bg-color">立即转账</a>
	</div>

{/block}
{block name="footer"}{/block}
{block name="script"}
<script>
	$(".password-div input").on("input",function(e){ //标签为password-div下的input添加oninput事件
		var number = 6;   //定义输入最大值
		var pw = $("input[name = 'password']").val(); //定义pw为name是password的input框的输入值
		var list = $(".password-div ul li");  //定义list是li
		//console.log(pw);
		for(var i = 0; i < number ; i++){    //for循环遍历将·放入li标签
			if(pw[i]){
				$(list[i]).text("·");
			}else{
				$(list[i]).text("");
			};
		};
		if(pw.length == 6){
			console.log('完成支付！')
			calculate(pw);
		}
	});


	$(".password-div ul").click(function(){
		$("input[name = 'password']").val("");
		$("#password").focus();
		$(".password-div ul li").text("");
	});

	function closePayPassword(){

		$(".pay-password-bg").hide()
		$(".pay-pass-bg-wrapper").hide()

	}
	function showPayPasswordDlg() {
		$(".pay-password-bg").show()
		$(".pay-pass-bg-wrapper").show()
	}


	var is_sub = false;
	function calculate(pw) {
		if(is_sub){
			return;
		}
		//alert(pw);
		var params = {pay_password: pw};
		is_sub = true;
		api("System.Member.checkPayPassword", params, function (res) {

			if(res['data'] === 1){
				btnSave()
			}else{
				toast("{:lang('member_pay_password_error')}");
				is_sub = false;
			}
		})
	}

	function btnSave() {
		var user_name = $("#user_name").val();
		var nick_name = $("#nick_name").val();
		var money = $("#money").val();
		money = Number(money);
		api('System.Member.transfer', {
			"user_name": user_name,
			"nick_name": nick_name,
			"money": money,
			"account_type": 3
		}, function (res) {
			console.log(res);
			if (res.data > 0) {
				toast(res.message);
				$("#password").val('');
				window.location.href = __URL(APPMAIN + "/member/index");
				is_sub = false;
			} else {
				toast(res.message);
			}
		})
	}
</script>
{/block}